package com.ruoyi.qiuyue.config;

import com.ruoyi.qiuyue.common.JWTUtils;
import com.ruoyi.qiuyue.interceptor.AuthFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 配置过滤路径
 */
@Configuration
public class WebConfig {
    @Autowired
    private JWTUtils jwtUtils;

    @Bean
    public FilterRegistrationBean<AuthFilter> filterFilterRegistrationBean(){
        FilterRegistrationBean<AuthFilter> bean = new FilterRegistrationBean<>();
        // 注册自定义过滤器
        bean.setFilter(new AuthFilter(jwtUtils));
        bean.setName("tokenFilter");
        // 过滤路径
        bean.addUrlPatterns("/app/user/*");
        // 过滤路径
        bean.addUrlPatterns("/app/favorite/*");
        bean.setOrder(0);
        // 需要排除的路径
        bean.addInitParameter("excludedUris",
                "/app/**");
        return bean;
    }
}
